﻿using System;
using System.IO;
using System.Text;

namespace CS.Log
{
    public class Logger
    {
        private static readonly string rootPath = AppDomain.CurrentDomain.BaseDirectory;

        public static bool Log(string logFile, string content)
        {
            return Log(logFile, content, false);
        }

        public static bool Log(string logFile, string content, bool logTime)
        {
            try
            {
                if (string.IsNullOrEmpty(logFile) || string.IsNullOrEmpty(content)) return false;
                var sb = new StringBuilder();
                if (logTime) sb.AppendLine(string.Format("[T={0:HH:ss:mm,ffff}]", DateTime.Now));
                sb.AppendLine(content);
                var path = string.Format("{0}/logs/{1}_{2}", rootPath, DateTime.Now.ToString("yyyyMMdd"), logFile);
                File.AppendAllText(path, sb.ToString(), Encoding.UTF8);
                return true;
            }
            catch (Exception)
            {
                return false;
                //throw;
            }
        }
      

        

        //public static bool Log(string logName, string content)
        //{
        //    try
        //    {
        //        if (string.IsNullOrEmpty(logName) || string.IsNullOrEmpty(content)) return false;
        //        var sb = new StringBuilder();
        //        sb.AppendLine(string.Format("[T:{0:HH:ss:mm,ffff}]", DateTime.Now));
        //        sb.Append(content);
                
        //        var path = string.Format("{0}/logs/{1}_{2}", rootPath, DateTime.Now.ToString("yyyy_MM_dd"), logFile);
        //        File.AppendAllText(path, sb.ToString(), Encoding.UTF8);
        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        return false;
        //        //throw;
        //    }

        //}

    }
}